<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Message extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->template->set_partial('header_search', 'header/header_search');
		$this->template->set_partial('nav_bar', 'header/nav_bar');
		$this->load->model('member/member_model');
		$this->load->model('member/profile_model');
		$this->load->model('member/article_model');
		$this->load->model('member/message_model');
		
	}
	
	function index()
	{
		
		$data['mode'] = "MESSAGE";
		/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
		
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			
			$data['profile']['info'] = $isProfile;
			
			$data['profile_id'] = $profile_id;
			$data['message']['details'] = $this->message_model->getMessage($profile_id);
		
			
			
		}else{
			$data['profile']['info'] = null;
		}
		/*GET PROFILE ID*/
		
		
		
		$this->template->set_layout('full_layout');
		$data['module_banner'] = FALSE;
		$data['module_recent_listing'] = TRUE;
		$data['module_news'] = FALSE;
		
		if($this->member_model->getMember($this->session->userdata['mem_id'])){
			$data['member']['info'] = $this->member_model->getMember($this->session->userdata['mem_id']);
		}
		
		$this->template->build('message',$data);
	}
	
	function view($id)
	{
		$data['mode'] = "VIEW";
	
		/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
	
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			$data['profile']['info'] = $isProfile;
			$data['profile_id'] = $profile_id;
		}else{
			$data['profile_id'] = null;
		}
		/*GET PROFILE ID*/
	
		$data['message']['info'] = $this->message_model->getMessageinfo($id);
	
		
		
		$this->template->set_layout('full_layout');
		$data['module_banner'] = FALSE;
		$data['module_recent_listing'] = TRUE;
		$data['module_news'] = FALSE;
	
		if($this->member_model->getMember($this->session->userdata['mem_id'])){
			$data['member']['info'] = $this->member_model->getMember($this->session->userdata['mem_id']);
		}
	
		$this->template->build('message',$data);
	
	}
	
	
	function delete($id)
	{
		$this->article_model->deleteArticle($id);
		redirect('member/article');
	}
	
	
}